package com.negotium.presentacion.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.negotium.context.BeanContainer;
import com.negotium.dominio.dao.UsuarioDAO;
import com.negotium.presentacion.web.form.UserInfoForm;

import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.userdetails.UserDetails;

public class UserInfoAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		UserInfoForm userinfo = (UserInfoForm) form;
		
		UserDetails loggedUser = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		UsuarioDAO usuarioDAO = (UsuarioDAO) BeanContainer.getBean("usuarioDAO");
		userinfo.setUsuario(usuarioDAO.findByUserName(loggedUser.getUsername()));
			
		return mapping.findForward("datosuser");
	}
	
}
